<%
# 
# Copyright (C) 2006  Warren Konkel and Bounty Source, Inc.
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
# 
%>
<p>
  <strong>Color Key:</strong>
  <span class="codetable_content_unchanged" style="border: 1px solid #bbb">unchanged text</span>
  <span class="codetable_content_changed" style="border: 1px solid #bbb">changed text</span>
  <span class="codetable_content_added" style="border: 1px solid #bbb">added text</span>
  <span class="codetable_content_removed" style="border: 1px solid #bbb">removed text</span>
</p>


<% count1 = 1 %>
<% count2 = 1 %>
<% queue1 = [] %>
<% queue2 = [] %>
<% if udiff.length > 0 %>
  <table class="codetable">
    <thead>
      <tr>
        <th colspan="2"><%=udiff[1][3..-1]%></th>
        <th colspan="2"><%=udiff[0][3..-1]%></th>
      </tr>
    </thead>

    <colgroup>
      <col />
      <col width="1*" />
      <col />
      <col width="1*" />
    </colgroup>
  
    <tbody>
      <% for line in udiff[2..-1] + ["*"] %>
        <% if line.match(/@@ -(\d+),\d+ \+(\d+),\d+ @@/) %>
          <%
            count1 = $1.to_i
            count2 = $2.to_i
          %>
          <tr class="codetable_content_blank">
            <th><span>&hellip;</span></th>
            <th></th>
            <th><span>&hellip;</span></th>
            <th></th>
          </tr>
        <% else %>
          <%
            case line[0..0]
              when '+'
                queue2 << line[1..-1]
                next
              when '-'
                queue1 << line[1..-1]
                next
              when ' '
                line = line[1..-1]
              when "\\"
                next
              when '*'
                # this is our magical "end of file" thingie
                line = nil
            end
          %>
    
          <% while (queue1.length > 0 || queue2.length > 0) %>
            <% if queue1.length > 0 && queue2.length > 0 %>
              <tr class="codetable_content_changed">
                <th><span><a name="l<%=(count1=count1+1)%>" href="#l<%=count1%>"><%=count1%></a></span></th>
                <td><span><%=hh(queue1.shift)%></span></td>
                <th><span><a name="r<%=(count2=count2+1)%>" href="#r<%=count2%>"><%=count2%></a></span></th>
                <td><span><%=hh(queue2.shift)%></span></td>
              </tr>
            <% elsif queue1.length > 0 %>
              <tr class="codetable_content_added">
                <th><span><a name="l<%=(count1=count1+1)%>" href="#l<%=count1%>"><%=count1%></a></span></th>
                <td><span><%=hh(queue1.shift)%></span></td>
                <th><span>&nbsp;</span></th>
                <td></td>
              </tr>
            <% elsif queue2.length > 0 %>
              <tr class="codetable_content_removed">
                <th><span>&nbsp;</span></th>
                <td></td>
                <th><span><a name="r<%=(count2=count2+1)%>" href="#r<%=count2%>"><%=count2%></a></span></th>
                <td><span><%=hh(queue2.shift)%></span></td>
              </tr>
            <% end %>
          <% end %>
    
          <% if !line.nil? %>
            <tr class="codetable_content_unchanged">
              <th><span><a name="l<%=(count1=count1+1)%>" href="#l<%=count1%>"><%=count1%></a></span></th>
              <td><span><%=hh(line)%></span></td>
              <th><span><a name="r<%=(count2=count2+1)%>" href="#r<%=count2%>"><%=count2%></a></span></th>
              <td><span><%=hh(line)%></span></td>
            </tr>
          <% else %>
            <tr class="codetable_content_blank">
              <th><span>&hellip;</span></th>
              <th></th>
              <th><span>&hellip;</span></th>
              <th></th>
            </tr>
          <% end %>
        <% end %>
      <% end %>
    </tbody>
  </table>
<% else %>
  No differences.
<% end %>